Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

Event.getPlace   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 3
loc 3
rs 10
1 View Code Duplication
var GedcomX = require('../'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    utils = require('../utils');
3
4
/**
5
 * An event.
6
 * 
7
 * @constructor
8
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
9
 */
10
var Event = function(json){
11
  
12
  // Protect against forgetting the new keyword when calling the constructor
13
  if(!(this instanceof Event)){
14
    return new Event(json);
15
  }
16
  
17
  // If the given object is already an instance then just return it. DON'T copy it.
18
  if(Event.isInstance(json)){
19
    return json;
20
  }
21
  
22
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
23
};
24
25
Event.prototype = Object.create(GedcomX.Subject.prototype);
26
27
Event._gedxClass = Event.prototype._gedxClass = 'GedcomX.Event';
28
29
Event.jsonProps = [
30
  'type',
31
  'date',
32
  'place',
33
  'roles'
34
];
35
36
/**
37
 * Check whether the given object is an instance of this class.
38
 * 
39
 * @param {Object} obj
40
 * @returns {Boolean}
41
 */
42
Event.isInstance = function(obj){
43
  return utils.isInstance(obj, this._gedxClass);
44
};
45
46
/**
47
 * Initialize from JSON
48
 * 
49
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
50
 * @return {Event} this
51
 */
52
Event.prototype.init = function(json){
53
  
54
  GedcomX.Subject.prototype.init.call(this, json);
55
  
56
  if(json){
57
    this.setType(json.type);
58
    this.setDate(json.date);
59
    this.setPlace(json.place);
60
    this.setRoles(json.roles);
61
  }
62
  return this;
63
};
64
65
/**
66
 * Get the type
67
 * 
68
 * @returns {String}
69
 */
70
Event.prototype.getType = function(){
71
  return this.type;
72
};
73
74
/**
75
 * Set the type
76
 * 
77
 * @param {String} type
78
 * @returns {Event}
79
 */
80
Event.prototype.setType = function(type){
81
  this.type = type;
82
  return this;
83
};
84
85
/**
86
 * Get the date
87
 * 
88
 * @returns {Date}
89
 */
90
Event.prototype.getDate = function(){
91
  return this.date;
92
};
93
94
/**
95
 * Set the date
96
 * 
97
 * @param {Date} date
98
 * @returns {Event}
99
 */
100
Event.prototype.setDate = function(date){
101
  if(date){
102
    this.date = GedcomX.Date(date);
103
  }
104
  return this;
105
};
106
107
/**
108
 * Get the place
109
 * 
110
 * @returns {PlaceReference}
111
 */
112
Event.prototype.getPlace = function(){
113
  return this.place;
114
};
115
116
/**
117
 * Set the place
118
 * 
119
 * @param {PlaceReference} place
120
 * @returns {Event}
121
 */
122
Event.prototype.setPlace = function(place){
123
  if(place){
124
    this.place = GedcomX.PlaceReference(place);
125
  }
126
  return this;
127
};
128
129
/**
130
 * Get the roles
131
 * 
132
 * @returns {EventRole[]}
133
 */
134
Event.prototype.getRoles = function(){
135
  return this.roles || [];
136
};
137
138
/**
139
 * Set the roles
140
 * 
141
 * @param {EventRole[]|Object[]} roles
142
 * @returns {Event}
143
 */
144
Event.prototype.setRoles = function(roles){
145
  return this._setArray(roles, 'roles', 'addRole');
146
};
147
148
/**
149
 * Add a role
150
 * 
151
 * @param {EventRole|Object} role
152
 * @returns {Event}
153
 */
154
Event.prototype.addRole = function(role){
155
  return this._arrayPush(role, 'roles', GedcomX.EventRole);
156
};
157
158
/**
159
 * Export the object as JSON
160
 * 
161
 * @return {Object} JSON object
162
 */
163
Event.prototype.toJSON = function(){
164
  return this._toJSON(GedcomX.Subject, Event.jsonProps);
165
};
166
167
module.exports = Event;